class_name BaseMap
extends Node2D

#region 属性
var map_manager:MapManager
var map_info:MapInfo
var room_dict:Dictionary[int,BaseRoom]
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
func get_room_by_direction(room_idx:int,direction:GameEnum.Direction) -> BaseRoom:
	if room_idx == -1:
		return null
	var row = (room_idx + 1) / map_info.map_shape.x - 1
	var col = (room_idx + 1) % map_info.map_shape.x - 1
	var target_pos = Vector2i(col,row) + Constant.Eight_DIR_OFFEST[direction]
	if target_pos.x < 0 or target_pos.x >= map_info.map_shape.x or target_pos.y < 0 or target_pos.y >= map_info.map_shape.y:
		return null
	var idx = target_pos.y * map_info.map_shape.x + target_pos.x
	return room_dict.get(idx,null)
func get_rooms_by_type(room_type:GameEnum.RoomType = -1) -> Array:
	if room_type == -1:
		return room_dict.values()
	return room_dict.values().filter(func(room:BaseRoom):return room.room_info.room_type == room_type)
func destroy():
	## 销毁所有房间
	for room:BaseRoom in room_dict.values():
		room.destroy_room()
	queue_free()
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init(map_manager:MapManager,map_info:MapInfo,room_dict:Dictionary[int,BaseRoom]) -> void:
	self.map_manager = map_manager
	self.map_info = map_info
	self.room_dict = room_dict
#endregion
